<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button onclick="mystop()"></button>
  <p id="demo"></p>
</body>

</html>
<script>
  var myvar = setInterval(() => {
    mytimer()
  }, 1000);

  function mytimer() {
    var d = new Date();
    var t = d.toLocaleTimeString();
    document.getElementById("demo").innerHTML = t;
  }

  function mystop() {
    clearInterval(myvar);
  }
</script>